<?php

namespace iBrand\Component\Order\Models;

use iBrand\Component\Goods\Models\Goods;
use iBrand\Component\User\Models\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Comment extends Model
{
	use SoftDeletes;

	protected $table = 'el_order_comment';

	protected $guarded = ['id'];

	const STATUS_SHOW   = 'show';
	const STATUS_HIDDEN = 'hidden';

	public function setItemMetaAttribute($value)
	{
		$this->attributes['item_meta'] = json_encode($value);
	}

	public function getItemMetaAttribute($value)
	{
		return json_decode($value, true);
	}

	public function user()
	{
		return $this->belongsTo(User::class);
	}

	public function setPicListAttribute($value)
	{
		$this->attributes['pic_list'] = serialize($value);
	}

	public function getPicListAttribute($value)
	{
		return unserialize($value);
	}

	public function goods()
	{
		return $this->belongsTo(Goods::class);
	}

	public function orderItem()
	{
		return $this->belongsTo(OrderItem::class, 'order_item_id');
	}

	public function getUserMetaAttribute()
	{
		return json_decode($this->attributes['user_meta'], true);
	}

}
